1 using UnityEngine;
2 using
System.Collections;
3 using
System;
4
5 public
class Scalable : MonoBehaviour {
6
7     
protected bool ready = false;
8
9     
protected Color origColor;
10     
protected Color origEmission;
11     
protected Material origMaterial;
12     
protected new Renderer renderer;
13
14     
protected virtual void Start() {
15         renderer = GetComponent<Renderer>();
16         origMaterial = GetComponent<Renderer>().material;
17         origColor = origMaterial.GetColor(
"_Color");
18         origEmission = origMaterial.GetColor(
"_EmissionColor");
19     }
20
21     
public bool IsReady {
22         
get {
23             
return ready;
24         }
25
26         
set {
27             ready =
value;
28         }
29     }
30
31     
public void SetMaterialOriginal() {
32         SetMaterial(origMaterial);
33     }
34
35     
public void SetEmissionOriginal() {
36         SetEmission(origEmission);
37     }
38
39     
public void SetColorOriginal() {
40         SetColor(origColor);
41     }
42
43     
public void SetMaterial(Material material) {
44         renderer.material = material;
45     }
46
47     
public void SetEmission(Color color) {
48         renderer.material.SetColor(
"_EmissionColor", color);
49         
//DynamicGI.UpdateMaterials(r);
50         
//DynamicGI.UpdateEnvironment();
51     }
52
53     
public void SetColor(Color color) {
54         renderer.material.SetColor(
"_Color", color);
55     }
56
57     
public void ScaleIn(float startAfter, float speed, float endScale) {
58         StartCoroutine(IEScaleIn(startAfter,speed,endScale));
59     }
60
61     
public void ScaleIn(float startAfter, float speed, Vector3 endScales) {
62         StartCoroutine(IEScaleIn(startAfter,speed,endScales));
63     }
64
65     
public void ScaleBy(float startAfter, float speed, float scaleBy) {
66         StartCoroutine(IEScaleBy(startAfter,speed,scaleBy));
67     }
68
69     
public void ScaleOut(float startAfter, float speed) {
70         StartCoroutine(IEScaleOut(startAfter, speed));
71     }
72
73     
public void ScaleOut(float startAfter, float speed, Action callback) {
74         StartCoroutine(IEScaleOut(startAfter, speed,callback));
75     }
76
77     
public IEnumerator IEScaleBy(float startAfter, float speed, float scaleBy) {
78         
yield return new WaitForSeconds(startAfter);
79
80         
float t = Time.deltaTime * speed;
81         
float scale = 1f;
82         
float diffScale = scaleBy - scale;
83         Vector3 origScale = gameObject.transform.localScale;
84         
while(t < Mathf.PI / 2) {
85             t += Time.deltaTime * speed;
86             gameObject.transform.localScale = origScale * (scale + diffScale * Mathf.Sin(t));
87             
yield return null;
88         }
89         gameObject.transform.localScale = origScale * scaleBy;
90     }
91
92     
public IEnumerator IEScaleIn(float startAfter, float speed, float endScale) {
93         
yield return new WaitForSeconds(startAfter);
94         ready =
false;
95         
float t = Time.deltaTime * speed;
96         
float scale = 1f;
97         
while(t < Mathf.PI / 2) {
98             t += Time.deltaTime * speed;
99             scale = endScale * Mathf.Sin(t);
100             transform.localScale =
new Vector3(scale,scale,scale);
101             
yield return null;
102         }
103         transform.localScale =
new Vector3(endScale, endScale, endScale);
104         ready =
true;
105     }
106
107     
public IEnumerator IEScaleIn(float startAfter, float speed, Vector3 endScales) {
108         
yield return new WaitForSeconds(startAfter);
109         ready =
false;
110         
float t = Time.deltaTime * speed;
111         
float scale = 1f;
112         
while(t < Mathf.PI / 2) {
113             t += Time.deltaTime * speed;
114             scale =
1f * Mathf.Sin(t);
115             transform.localScale = endScales * scale;
116             
yield return null;
117         }
118         transform.localScale = endScales * scale;
119         ready =
true;
120     }
121
122     
public IEnumerator IEScaleOut(float startAfter, float speed) {
123         
yield return IEScaleOutBase(startAfter, speed);
124         Destroy(gameObject);
125     }
126
127     
public IEnumerator IEScaleOut(float startAfter, float speed, Action callback) {
128         
yield return IEScaleOutBase(startAfter,speed);
129         callback();
130         Destroy(gameObject);
131     }
132
133     IEnumerator IEScaleOutBase(
float startAfter, float speed) {
134         
yield return new WaitForSeconds(startAfter);
135
136         
float t = Time.deltaTime * speed;
137         
float scale = 1f;
138         Vector3 origScale = gameObject.transform.localScale;
139         t = Mathf.PI /
2f;
140         
while(t < Mathf.PI) {
141             t += Time.deltaTime * speed;
142             scale =
1 * Mathf.Sin(t);
143             gameObject.transform.localScale = origScale * scale;
144             
yield return null;
145         }
146     }
147 }


DynamicGI.UpdateMaterials(r);

DynamicGI.UpdateEnvironment();



Gõ tìm kiếm nhanh...